package com.zhuss.product.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.product.preline.DeletePrelineSignBo;
import com.zhuss.bean.vo.product.preline.DetailPrelineSignVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.product.db.dao.ext.PrelineSignDao;
import com.zhuss.product.db.entity.PrelineSign;
import com.zhuss.util.JsonUtil;

/**
 * @description: 招募报名删除
 * @author: zhushanshuo
 * @create: Wed Jan 06 16:26:20 CST 2021
 **/
@Component("prelineSignDelete")
public class PrelineSignDelete extends AbstractProcessor<Object, DeletePrelineSignBo> implements Processor<Object, DeletePrelineSignBo> {

    @Autowired
    private PrelineSignDao prelineSignDao;
    
    @Autowired
	@Qualifier("prelineSignRead")
	private PrelineSignRead prelineSignRead;
    
    
    /**
     * 校验
     */
	@Override
    public void check(DeletePrelineSignBo bo) throws DzcxException {
		// 删除 招募报名 校验， 请补充
		DetailPrelineSignVo bean = new DetailPrelineSignVo();
		bean.setPrelineId(bo.getPrelineId());
		bean.setCreatorId(bo.getConcurrentUserId());
		DetailPrelineSignVo sign = prelineSignRead.getDetail(bean);
		if (sign == null) {
			throw new DzcxException(ExceptionCode.新线招募未报名);
		}
		bo.setPrelineSignId(sign.getPrelineSignId());
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeletePrelineSignBo param) throws DzcxException {
    	Long prelineId = param.getPrelineId();
		DetailPrelineSignVo bean = new DetailPrelineSignVo();
		bean.setPrelineId(prelineId);
		bean.setCreatorId(param.getConcurrentUserId());
		DetailPrelineSignVo vo =   prelineSignRead.getDetail(bean);
    	String name = vo.getName();
    	
    	PrelineSign record = new PrelineSign();
    	record.setPrelineSignId(vo.getPrelineSignId());
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	prelineSignDao.delete(record);
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeletePrelineSignBo param) throws DzcxException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.商品.key());
    	record.setAction(LogActionEnum.取消报名.key());
    	record.setTargetId(param.getPrelineSignId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
